/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package merlion.crm.slcm.entity;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import merlion.common.entity.SecurityRole;
import merlion.common.entity.Staff;
import merlion.common.util.Consts;
import merlion.crm.sopm.entity.PurchaseOrder;
import merlion.crm.sopm.entity.SalesOrder;
import merlion.frm.ccm.entity.CreditAccount;

/**
 *
 * @author Hong
 */
@Entity
@NamedQuery(name = "getAllCustomer", query = "SELECT c from Customer c")
public class Customer extends SalesLead implements Serializable {

    private static final long serialVersionUID = 1L;
    @OneToOne(targetEntity = CreditAccount.class, cascade = {CascadeType.ALL}, fetch = FetchType.EAGER)
    private CreditAccount creditAccount;
    @ManyToOne(targetEntity = MemberDiscountGroup.class, cascade = {CascadeType.ALL})
    private MemberDiscountGroup memberDiscountGroup;
    @OneToMany(targetEntity = PurchaseOrder.class, cascade = {CascadeType.ALL}, fetch = FetchType.EAGER, mappedBy = "customer")
    private Collection<PurchaseOrder> purchaseOrders;
    @OneToMany(targetEntity = SalesOrder.class, cascade = {CascadeType.ALL}, fetch = FetchType.EAGER, mappedBy = "customer")
    private Collection<SalesOrder> salesOrders;
    @OneToOne(targetEntity = Address.class, cascade = {CascadeType.ALL}, fetch = FetchType.EAGER)
    private Address billingAddress;
    private Double accumulatedPurchases;

    //--------------------------------------------------------------------------
    //                            Constructor
    //--------------------------------------------------------------------------
    public Customer() {
        creditAccount = null;
        purchaseOrders = new ArrayList<PurchaseOrder>();
        salesOrders = new ArrayList<SalesOrder>();
        billingAddress = new Address();
        accumulatedPurchases = (double) 0.0;
    }

    //--------------------------------------------------------------------------
    //                      Getter and Setter
    //--------------------------------------------------------------------------
    public Collection<SalesOrder> getSalesOrders() {
        return salesOrders;
    }

    public void setSalesOrders(Collection<SalesOrder> salesOrders) {
        this.salesOrders = salesOrders;
    }

    public CreditAccount getCreditAccount() {
        return creditAccount;
    }

    public void setCreditAccount(CreditAccount creditAccount) {
        this.creditAccount = creditAccount;
    }

    public MemberDiscountGroup getMemberDiscountGroup() {
        return memberDiscountGroup;
    }

    public void setMemberDiscountGroup(MemberDiscountGroup memberDiscountGroup) {
        this.memberDiscountGroup = memberDiscountGroup;
    }

    public Collection<PurchaseOrder> getPurchaseOrders() {
        return purchaseOrders;
    }

    public void setPurchaseOrders(Collection<PurchaseOrder> purchaseOrders) {
        this.setPurchaseOrders(purchaseOrders);
    }

    public Address getBillingAddress() {
        return billingAddress;
    }

    public void setBillingAddress(Address billingAddress) {
        this.billingAddress = billingAddress;
    }

    public Double getAccumulatedPurchases() {
        return accumulatedPurchases;
    }

    public void setAccumulatedPurchases(Double accumulatedPurchases) {
        this.accumulatedPurchases = accumulatedPurchases;
    }


    //--------------------------------------------------------------------------
    //                          Entity Methods
    //--------------------------------------------------------------------------
    //--------------------------------------------------------------------------
    //                          Object Methods
    //--------------------------------------------------------------------------
    @Override
    public int hashCode() {
        int hash = 0;
        hash += (getId() != null ? getId().hashCode() : 0);
        return hash;
    }

    @Override
    public String toString() {
        return "merlion.crm.sopm.entity.Customer[ id=" + getId() + " ]";
    }
}
